package com.gp.testonline.service.impl;

import com.gp.testonline.dao.ExamquestionMapper;
import com.gp.testonline.eo.ExamquestionEOPage;
import com.gp.testonline.model.Examquestion;
import com.gp.testonline.service.ExamquestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *实现业务及流程接口当中的内容
 */
@Service
public class ExamquestionServiceImpl implements ExamquestionService {
    @Autowired
    private ExamquestionMapper examquestionMapper;

    @Override
    public int InsertExamquestion(Examquestion examquestion) {
        int isInsert=0;
        /*
         * 业务判断
         * 试题号不能重复
         */
        int examnumberCount=examquestionMapper.getEqnumberCount(examquestion.getEqnumber());
        if (examnumberCount<1){
            //返回值
            isInsert=examquestionMapper.insertExamquestion(examquestion);
        }else{
            isInsert=-1;//有相同试题号
        }
        return isInsert;
    }

    @Override
    public int UpdateExamquestion(Examquestion examquestion) {
        int isUpdate=0;
        /*
         * 业务判断
         * 试题号不能重复
         */
        int examnumberCount=examquestionMapper.getEqnumberCount(examquestion.getEqnumber());
        if (examnumberCount<1){
            //返回值
            isUpdate=examquestionMapper.updateExamquestion(examquestion);
        }else{
            isUpdate=-1;//有相同试题号
        }
        return isUpdate;
    }

    @Override
    public int DeleteExamquestion(Integer eqid) {
        int isDelete=0;
        /*1 没有相关业务流程的判断*/
        try{
            isDelete=examquestionMapper.deleteExamquestion(eqid);
        }catch (Exception e){
            isDelete=-1;
            //打印更新时报错的情况
            System.out.println("删除试题信息时执行sql报错的原因为："+e.getMessage());
        }
        return isDelete;
    }

    @Override
    public List<ExamquestionEOPage> getExamquestionAll(ExamquestionEOPage examquestionEOPage) {
        List<ExamquestionEOPage> listExamquestionEo=examquestionMapper.getExamquestionAll(examquestionEOPage);
        return listExamquestionEo;
    }
}
